﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skynet.WebAdministracion.Views.DesignExamViewer;
using Microsoft.Practices.Unity;

namespace Skynet.WebSite.Administration
{
    public partial class DesignExamViewerView : Infrastructure.Web.Views.Page, IDesignExamViewerView
    {
        private DesignExamViewerPresenter _Presenter;

        [Dependency]
        public DesignExamViewerPresenter Presenter
        {
            get { return _Presenter; }
            set
            {
                _Presenter = value;
                this._Presenter.View = this;
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            var result = this.Request["ctl00$MainContent$txtNumberOfQuestions"];

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.odsAlternatives.ObjectCreating += delegate(object ocds, ObjectDataSourceEventArgs args) { args.ObjectInstance = this.Presenter; };
            if (!Page.IsPostBack)
            {
                this.Presenter.OnViewInitialized();
            }
            else
                this.Presenter.OnViewLoaded();
        }

        protected void lbQuestions_Click(object sender, EventArgs e)
        {
            this.Presenter.BackToExams();
            
        }
        public string ExamTitle { set { this.lblExamTitle.Text = value; } }
        public string QuestionCategory { get { return this.txtCategory.Text; } set { this.txtCategory.Text = value; } }
        public string QuestionTitle { get { return this.txtTitle.Text; } set { this.txtTitle.Text = value; } }
        public string QuestionType { get { return this.ddlQuestionType.SelectedValue; } set { } }
        public Control QuestionControl { 
            get {
                Control result = null;
                foreach (var item in this.pnQuestion.Controls)
                {
                    if (item is Skynet.WebFoundation.Controls.Design.TextQuestionControl)
                    {
                        result = item  as Control; break;
                    }                    
                }
                return result;
            } 
            set { this.pnQuestion.Controls.Add(value); } }



        protected void lbNewQuestion_Click(object sender, EventArgs e)
        {
            this.Presenter.NewQuestion();
            
        }
        protected void ddlQuestionType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.gvAlternatives.SelectedValue != null)
                this.Presenter.ShowAlternative((Guid)this.gvAlternatives.SelectedValue);
        }

        protected void lbNewAlternative_Click(object sender, EventArgs e)
        {
            this.Presenter.NewAlternative();
        }
    }
}